﻿Public Class BLLPaSala
    Dim objDAL As DALPaSala
    Private codigo As Integer
    Private sala As String
    Private hinicio As DateTime
    Private hfinal As DateTime
    Private coddia As Integer
    Private codsala As Integer
    Private descricao As String
    Public Sub New()

    End Sub
#Region "Propriedades"
    Public Property pdescricao As String
        Get
            Return Me.descricao
        End Get
        Set(ByVal value As String)
            Me.descricao = value
        End Set
    End Property
    Public Property pcodsala As Integer
        Get
            Return Me.codsala
        End Get
        Set(ByVal value As Integer)
            Me.codsala = value
        End Set
    End Property
    Public Property psala As String
        Get
            Return Me.sala
        End Get
        Set(ByVal value As String)
            Me.sala = value
        End Set
    End Property
    Public Property pcodigo As Integer
        Get
            Return Me.codigo
        End Get
        Set(ByVal value As Integer)
            Me.codigo = value
        End Set
    End Property
    Public Property phinicio As DateTime
        Get
            Return Me.hinicio
        End Get
        Set(ByVal value As DateTime)
            Me.hinicio = value
        End Set
    End Property
    Public Property phfinal As DateTime
        Get
            Return Me.hfinal
        End Get
        Set(ByVal value As DateTime)
            Me.hfinal = value
        End Set
    End Property
    Public Property pcoddia As Integer
        Get
            Return Me.coddia
        End Get
        Set(ByVal value As Integer)
            Me.coddia = value
        End Set
    End Property
#End Region

#Region "Métodos"
    Function excluir(ByVal cod As Integer) As Boolean
        Dim ret As Boolean
        Try
            objDAL = New DALPaSala
            ret = objDAL.excluir(cod)
        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
        If ret = True Then
            Return True
        Else
            Return False
        End If
    End Function
    Function inserir() As Integer
        Dim ret As Boolean
        Dim erro As Integer
        Try
            objDAL = New DALPaSala
            If FormatDateTime(Me.hinicio, vbShortTime) < FormatDateTime(Me.hfinal, vbShortTime) Then
                If ValidaAlterar() Then
                    ret = objDAL.inserir(Me.hinicio, Me.hfinal, Me.coddia, Me.codsala, Me.descricao)
                    If ret = True Then
                        erro = 0
                    Else
                        erro = 10
                    End If
                Else
                    erro = 2
                End If
            Else
                erro = 1
            End If

        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
        Return erro

    End Function
    Function Alterar() As Integer
        Dim ret As Boolean
        Dim erro As Integer
        Try
            objDAL = New DALPaSala
            If FormatDateTime(Me.hinicio, vbShortTime) < FormatDateTime(Me.hfinal, vbShortTime) Then
                If ValidaAlterar() Then
                    ret = objDAL.Alterar(Me.codigo, Me.hinicio, Me.hfinal, Me.coddia, Me.codsala, Me.descricao)
                    If ret = True Then
                        erro = 0
                    Else
                        erro = 10
                    End If
                Else
                    erro = 2
                End If
            Else
                erro = 1
            End If

        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
        Return erro

    End Function
    Function ValidaInsere() As Boolean
        Dim tab As DataTable
        Try
            objDAL = New DALPaSala
            tab = objDAL.ValidaInsere(Me.coddia, Me.codsala, Me.hinicio, Me.hfinal)
            For Each linha As DataRow In tab.Rows
                linha("sal_codigo").ToString()
                Return False
            Next
        Catch ex As Exception
            Throw ex
        Finally

        End Try
        Return True
    End Function
    Function ValidaAlterar() As Boolean
        Dim tab As DataTable
        Try
            objDAL = New DALPaSala
            tab = objDAL.ValidaAlterar(Me.codigo, Me.coddia, Me.codsala, Me.hinicio, Me.hfinal)
            For Each linha As DataRow In tab.Rows
                linha("sal_codigo").ToString()
                Return False
            Next
        Catch ex As Exception
            Throw ex
        Finally

        End Try
        Return True
    End Function
    'Function localizar() As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAL = New DALPaSala
    '        tab = objDAL.localizar()
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAL = Nothing
    '    End Try
    '    Return tab
    'End Function
    'Function localizar(ByVal descricao As String) As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAL = New DALPaSala
    '        tab = objDAL.localizar(descricao)
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAL = Nothing
    '    End Try
    '    Return tab
    'End Function
    'Function localizar(ByVal cod As Integer) As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAL = New DALPaSala
    '        tab = objDAL.localizar(cod)
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAL = Nothing
    '    End Try
    '    Return tab
    'End Function
    'Function LocalizarDia(ByVal dia As String) As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAL = New DALPaSala
    '        tab = objDAL.localizarDia(dia)
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAL = Nothing
    '    End Try
    '    Return tab

    'End Function
    'Function LocalizarDia_Sala(ByVal dia As String, ByVal cod As Integer) As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAL = New DALPaSala
    '        tab = objDAL.localizarDia_Sala(dia, cod)
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAL = Nothing
    '    End Try
    '    Return tab

    'End Function
    'Function Localizartudo() As DataTable
    '    Dim tab As DataTable
    '    Try
    '        objDAL = New DALPaSala
    '        tab = objDAL.localizartudo()
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objDAL = Nothing
    '    End Try
    '    Return tab

    'End Function
    Function Localizartudo(ByVal Filtro As String) As DataTable
        Dim tab As DataTable
        Try
            objDAL = New DALPaSala
            tab = objDAL.localizartudo(Filtro)
        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
        Return tab

    End Function
    Function LocalizaParticularidade(ByVal codigo As Integer, ByVal filtro As String) As DataTable
        Dim tab As DataTable
        Try
            objDAL = New DALPaSala
            tab = objDAL.LocalizaParticularidade(codigo, filtro)
        Catch ex As Exception
            Throw ex
        Finally
            objDAL = Nothing
        End Try
        Return tab

    End Function

#End Region
End Class
